//
//  MeViewController.m
//  JJHW_coreData
//
//  Created by lizhenqiang on 16/4/8.
//  Copyright © 2016年 HFKJ_LZQ. All rights reserved.
//

#import "MeViewController.h"
//#import "MBProgressHUD.h"
#import "LoginViewController.h"
#import "ResetPasswdViewController.h"
#import "MeUpTableViewCell.h"
#import "MorecommonCell.h"

#import "MyAppraiseViewController.h"
#import "SystemMessageViewController.h"
#import "MyMainPageViewController.h"
#import "ChangePasswdViewController.h"
#import "ThirdAcountBindViewController.h"

@interface MeViewController ()<UITableViewDelegate,UITableViewDataSource>

@property(strong,nonatomic)NSArray *commonCellDataArray;
@end

@implementation MeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, DeviceWidth, DeviceHeight-49) style:UITableViewStylePlain];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.view addSubview:self.tableView];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.tableView registerNib:[UINib nibWithNibName:@"MeUpTableViewCell" bundle:nil] forCellReuseIdentifier:@"MeUpTableViewCell"];
    [self.tableView registerNib:[UINib nibWithNibName:@"MorecommonCell" bundle:nil] forCellReuseIdentifier:@"MorecommonCell"];
    _commonCellDataArray = @[@{@"content":@"我的评论",@"image":@"icon_pinglun"},@{@"content":@"系统消息",@"image":@"icon_xtxx"},@{@"content":@"我的主页",@"image":@"icon_grxx"},@{@"content":@"修改密码",@"image":@"icon_xgmm"},@{@"content":@"第三方账号绑定",@"image":@"icon_zhbd"}];
    
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:YES];
    [self.navigationController setNavigationBarHidden:YES animated:NO];
    
}
-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:YES];
    [self.navigationController setNavigationBarHidden:NO animated:NO];
}
//-(void)loadDataWithCurrentpage:(NSInteger)currentpage
//{
//    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
//    for (int i=0; i<10; i++) {
//        NSString *str = [NSString stringWithFormat:@"%d",i];
//        [self.pageDataArr addObject:str];
//    }
//    
//    [MBProgressHUD hideHUDForView:self.view animated:YES];
//    [self.tableView reloadData];
//    [self.tableView.mj_footer endRefreshing];
//    [self.tableView.mj_header endRefreshing];
//}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.commonCellDataArray.count+2;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row==0) {
        return kScaleFrom_iphone6_Desgin(290)+60;//kScaleFrom_iphone6_Desgin(350);
    }
    else if (indexPath.row==1)
    {
        return 10;
    }
    else
    {
        return 50;
    }
}

//-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
//{
//    if (indexPath.row==0) {
////        return kScaleFrom_iphone6_Desgin(350);
//        return [tableView fd_heightForCellWithIdentifier:@"MeUpTableViewCell" cacheByIndexPath:indexPath configuration:^(MeUpTableViewCell *cell) {
//            [self configureCell:cell atIndexPath:indexPath];
//        }];
//    }
//    else if (indexPath.row==1)
//    {
//        return 10;
//    }
//    else
//    {
//        return [tableView fd_heightForCellWithIdentifier:@"MorecommonCell" cacheByIndexPath:indexPath configuration:^(MorecommonCell *cell) {
//            [self configureCell:cell atIndexPath:indexPath];
//        }];
//    }
//    
//    
//}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
        MeUpTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MeUpTableViewCell"];
        cell.VC = self;
        return cell;
    }
    else if (indexPath.row == 1)
    {
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"common"];
        if (cell == nil) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"common"];
        }
        cell.backgroundColor = kDefaultGrayColor;
        return cell;
        
    }
    else
    {
        MorecommonCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MorecommonCell"];
        NSDictionary *dic = self.commonCellDataArray[indexPath.row-2];
        [cell setCellData:dic];
        return cell;
    }
    
    return nil;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//    if (indexPath.row==0) {
//        
//        LoginViewController *login = [[LoginViewController alloc] initWithNibName:@"LoginViewController" bundle:nil];
//        BaseNavigationController *nav = [[BaseNavigationController alloc] initWithRootViewController:login];
//        [self.navigationController presentViewController:nav animated:YES completion:nil];
//        
//    }
//    else if (indexPath.row==1)
//    {
//        ResetPasswdViewController *reset = [[ResetPasswdViewController alloc] initWithNibName:@"ResetPasswdViewController" bundle:nil];
//        [self.navigationController pushViewController:reset animated:YES];
//    }
    
    if (indexPath.row>1) {
        switch (indexPath.row) {
            case 2:
            {//我的评论
                MyAppraiseViewController *appraise = [[MyAppraiseViewController alloc] initWithNibName:@"MyAppraiseViewController" bundle:nil];
                [self.navigationController pushViewController:appraise animated:YES];
            }
                break;
            case 3:
            {//系统消息
                SystemMessageViewController *message = [[SystemMessageViewController alloc] initWithNibName:@"SystemMessageViewController" bundle:nil];
                 [self.navigationController pushViewController:message animated:YES];
            }
                break;
            case 4:
            {//我的主页
                MyMainPageViewController *main = [[MyMainPageViewController alloc] initWithNibName:@"MyMainPageViewController" bundle:nil];
                 [self.navigationController pushViewController:main animated:YES];
            }
                break;
            case 5:
            {//修改密码
                ChangePasswdViewController *change = [[ChangePasswdViewController alloc] initWithNibName:@"ChangePasswdViewController" bundle:nil];
                 [self.navigationController pushViewController:change animated:YES];
            }
                break;
            case 6:
            {//第三方账号绑定
                
                ThirdAcountBindViewController *third = [[ThirdAcountBindViewController alloc] initWithNibName:@"ThirdAcountBindViewController" bundle:nil];
                 [self.navigationController pushViewController:third animated:YES];
            }
                break;
                
            default:
                break;
        }
    }
    
    
}


//- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
//    return 1;
//}
//
//- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
//    return self.pageDataArr.count;
//}
//-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
//{
//    return [tableView fd_heightForCellWithIdentifier:@"SearchViewCell" cacheByIndexPath:indexPath configuration:^(SearchViewCell *cell) {
//        [self configureCell:cell atIndexPath:indexPath];
//    }];
//}
//- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
//{
//    // in subClass
//    SearchViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SearchViewCell"];
//   
//    return cell;
//}
- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath
{
//    if (indexPath.row == 0) {
//         cell.fd_enforceFrameLayout = NO ;
//        MeUpTableViewCell *tcell = (MeUpTableViewCell *)cell;
//        
//    }
//    else if (indexPath.row == 1)
//    {
//         cell.fd_enforceFrameLayout = NO ;
//        
//    }
//    else
//    {
//         cell.fd_enforceFrameLayout = NO ;
//        MorecommonCell *tcell = (MorecommonCell *)cell;
//        NSDictionary *dic = self.commonCellDataArray[indexPath.row-2];
//        [tcell setCellData:dic];
//    }
}

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{//只对于自定义的cell  才会把cell下面的线条 完整填满。
    
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
